//
//  HSBasicTableViewController.swift
//  HomeSchoolDemo
//
//  Created by rimi on 16/10/8.
//  Copyright © 2016年 黄华强. All rights reserved.
//

import UIKit

class HSBasicTableViewController: UITableViewController {

    let refreshC = HHQRefreshControl()
    //记录刷新状态的属性
    var isPull: Bool = false

    override func viewDidLoad() {
        super.viewDidLoad()
         tableView.addSubview(refreshC)
        //设置监听
        refreshC.addTarget(self, action: #selector(loadData), for: .valueChanged)
      
    }

    func loadData() {
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
}

extension HSBasicTableViewController {
    //即将显示某行时调用
    override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        //获得当前行号
        let row = indexPath.row
        let section = tableView.numberOfSections - 1
        if row < 0 || section < 0 {
            return
        }
        let lastRows = tableView.numberOfRows(inSection: section) - 1
        
        if (indexPath.section == section) && (row == lastRows) && !isPull {
            isPull = true
            loadData()
        }
        
    }
    
}
